import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Title: Trie字符串统计
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/5 21:04
 * @description:
 */
public class Trie字符串统计 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, Integer>mp = new HashMap<>();

        for (int i = 1; i <= n; ++ i ) {
            String q = sc.next();
            String s = sc.next();

            if("I".equals(q)) {
                mp.merge(s, 1, Integer::sum); // 存在就+1 不存在就赋值为1
            } else {
                if(mp.containsKey(s)) {
                    System.out.println(mp.get(s));
                } else {
                    System.out.println(0);
                }
            }
        }
    }
}
